package com.hertz.alarm.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtil {
	private static Map<String, Pattern> patternMap = new HashMap<String, Pattern>();
	
	public static Collection<String> matcher(String content, String regex) {
		Collection<String> ret=new HashSet<String>();
		Pattern p = patternMap.get(regex);
		if(p == null){
			p = Pattern.compile(regex);
			patternMap.put(regex, p);
		}
		Matcher matcher = p.matcher(content);
		while(matcher.find()){
			ret.add(matcher.group());
		}
		return ret;
	}
}
